package teaching.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import teaching.pojo.Homework;
import teaching.pojo.Submission;

import java.util.List;
import java.util.Map;

/**
 * Author:20201002983_郑雨蓓
 * Date: 2024/3/18
 * Description:
 */
public interface HomeworkMapper extends BaseMapper<Homework> {
    @Select("select * from homework where cid=#{cid}")
    List<Homework> getHomeworkByCid(Long cid);

    @Insert("insert into homework(cid,title,content,due_date,userId) values (#{homework.cid},#{homework.title},#{homework.content},#{homework.dueDate},#{homework.userId})")
    int add(@Param("homework") Homework homework);

    @Delete("delete from homework where id=#{id}")
    int deleteHomework(Long id);

    @Update("ALTER TABLE `homework` AUTO_INCREMENT = 1")
    void resetAutoIncrement();

    //    @Select("select homework.*,score from homework,submission " + "where homework.cid=#{cid} and submission.homework_id=homework.id")
    List<Homework> listStudentHomework(@Param("cid") Long cid, @Param("studentId") Long studentId);

    @Insert("insert into submission (student_id, homework_id, homework_file, submission_date, score) " +
            "values (#{submission.studentId}, #{submission.homeworkId}, #{submission.homeworkFile}, #{submission.submissionDate}, #{submission.score})")
    int addSubmission(@Param("submission") Submission submission);

    List<Submission> homeworkSubmission(long homeworkId);

    int updateSubmission(@Param("submission") Submission submission);
}
